package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.GmallThreadLocalUtils;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.service.UserAddressService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 * 用户地址表的service层接口的实现类
 */
@Service
public class UserAddressServiceImpl implements UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    /**
     * 查询用户的所有地址
     *
     * @return
     */
    @Override
    public List<UserAddress> listByUsername() {
        List<UserAddress> userAddressList = userAddressMapper.selectList(
                new LambdaQueryWrapper<UserAddress>()
                        .eq(UserAddress::getUserId, GmallThreadLocalUtils.get()));

        return userAddressList;
    }
}
